package flow.service;

import flow.model.FlowBusiness;
import flow.model.FlowInstanceSection;
import flow.model.FlowSectionLink;
import m.common.service.Service;
import m.system.exception.MException;

import java.util.List;

public abstract class FlowService extends Service implements IFlowService {
    /** 根据section和business返回下一步可操作环节
     * 默认实现方式
     * 若需根据业务判断 可覆盖
     */
    @Override
    public List<FlowSectionLink> nextSectionLink(List<FlowSectionLink> links, FlowInstanceSection section, FlowBusiness business) {
        return links;
    }

    /**
     * 预创建并启动流程业务信息
     */
    public FlowBusiness createFlowBusiness(String adminOid,String deptOid,String oid,String service,String param) throws Exception {
        FlowBusiness business=getService(FlowBusinessService.class).createFlowBusiness(adminOid, deptOid, oid, "", "", service, param);
        getService(FlowInstanceService.class).doStart(business);
        return business;
    }
    /**
     * 更新业务描述
     */
    public void updateBusinessDesc(String oid,String type,String title) throws Exception {
        getService(FlowBusinessService.class).updateBusinessDesc(oid,type,title);
    }
    /** oid 业务主键
     * 设置下一步默认人
     * selectable 是否可以修改
     */
    public void setNextDefaultUser(String oid,String[] admins, boolean selectable) throws MException {
        getService(FlowBusinessService.class).updateNextDefaultUser(oid,admins,selectable);
    }

    /**
     * 设置下一步选人限制  指定部门和指定角色限制
     */
    public void setNextUser4Limit(String oid,String[] toOrg,String[] toRole) throws MException {
        getService(FlowBusinessService.class).updateNextUser4Limit(oid,toOrg,toRole);
    }
    /**
     * 设置下一步选人限制  录入人部门和指定角色限制
     */
    public void setNextUser4Dept(String oid,String... toDept) throws MException {
        getService(FlowBusinessService.class).updateNextUser4Dept(oid,toDept);
    }
    /**
     * 设置下一步选人限制  录入人机构和指定角色限制
     */
    public void setNextUser4Org(String oid,String... toOrg) throws MException {
        getService(FlowBusinessService.class).updateNextUser4Org(oid,toOrg);
    }
}